export default {
	twoWay: true,
	bind: function () {
		this.handler = () => {
			this.set(this.el.innerHTML);
			addEmpty(this);
		}
		this.el.addEventListener('keyup', this.handler);
	},
	update: function (value) {
		this.el.innerHTML = value || '';
		addEmpty(this);
	},
	unbind: function () {
		this.el.removeEventListener('keyup', this.handler);
	}
}

function addEmpty(vm) {
	var position = vm.el.className.indexOf(' empty');
	if (vm.el.innerHTML === '') {
		vm.el.className += ' empty';
	} else if (position > 0) {
		vm.el.className = vm.el.className.substring(0, position)
	}
}